package com.developmentReformProject.service.impl;

import com.developmentReformProject.dao.AdminDao;
import com.developmentReformProject.dao.EnterpriseDao;
import com.developmentReformProject.dto.EnterpriseDto;
import com.developmentReformProject.dto.EnterpriseQueryDto;
import com.developmentReformProject.dto.ProjectQueryDto;
import com.developmentReformProject.entity.Admin;
import com.developmentReformProject.entity.Apply;
import com.developmentReformProject.entity.Enterprise;
import com.developmentReformProject.service.EnterpriseService;
import com.developmentReformProject.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EnterpriseServiceImpl implements EnterpriseService {
    @Autowired
    private EnterpriseDao enterpriseDao;
    private AdminDao adminDao;
    @Override
    public String registerEnterprise(Enterprise enterprise) {
        enterpriseDao.addEnterprise(enterprise);
        return null;
    }

    @Override
    public int updatePasswordEnterprise(String accountNumber,String newPassword,String oldPassword) {
        String enterprisePassword=enterpriseDao.queryPassword(accountNumber);
        if(enterprisePassword!=null) {
            if (enterprisePassword.equals(oldPassword)) {
                enterpriseDao.updateEnterprisePassword(accountNumber, newPassword);
            } else {
                return 0;
            }
        }
        return 1;
    }

    @Override
    public String updateEnterprise(Enterprise enterprise) {
        enterpriseDao.updateEnterprise(enterprise);
        return null;
    }

    @Override
    public String loginEnterprise(String enterpriseAccountNumber, String enterprisePassword) {
        Enterprise login=enterpriseDao.enterpriseLogin(enterpriseAccountNumber,enterprisePassword);
        if(login!=null){
            return "成功";
        }else{
            return "失败";
        }
    }

    @Override
    public String logoutEnterprise(EnterpriseDto enterpriseDto) {
        return null;
    }

    @Override
    public String projectApplication(Apply apply) {
        return null;
    }

    @Override
    public String viewProjectAuditProgress(Integer enterpriseId) {
        enterpriseDao.queryAuditStatus(enterpriseId);
        return null;
    }

    @Override
    public ProjectQueryDto viewProject(Integer enterpriseId) {

        return null;
    }

    @Override
    public PageUtil<Enterprise> pageList(EnterpriseQueryDto enterpriseQueryDto) throws Exception {
        PageUtil<Enterprise> pageUtil=null;
        //统计满足条件记录总数
        int total=enterpriseDao.countSelective(enterpriseQueryDto);
        /*
         * 如果total>0,查询数据
         * 封装到pageUtil
         */
        if(total>0){
            List<Enterprise> data=enterpriseDao.selectSelective(enterpriseQueryDto);
            pageUtil=new PageUtil<>(total, data,enterpriseQueryDto.getCurrentPage(), enterpriseQueryDto.getPageSize());
        }
        return pageUtil;
    }

    @Override
    public PageUtil<Enterprise> cleanEnterprise(EnterpriseQueryDto enterpriseQueryDto) throws Exception {
        PageUtil<Enterprise> pageUtil=null;
        //统计满足条件记录总数
        int total=enterpriseDao.countClean(enterpriseQueryDto);
        /*
         * 如果total>0,查询数据
         * 封装到pageUtil
         */
        if(total>0){
            List<Enterprise> data=enterpriseDao.listDelete(enterpriseQueryDto);
            pageUtil=new PageUtil<>(total, data, enterpriseQueryDto.getCurrentPage(), enterpriseQueryDto.getPageSize());
        }
        return pageUtil;
    }
}
